﻿namespace SRM.DataObjects
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.ComponentModel;
    using System.Data;
    using System.Data.SqlClient;

    /// <summary>
    /// Summary description for SRM_Awards
    /// </summary>
    [DataObjectAttribute(true)]
    public class SRM_Awards
    {

        [DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
        public static DataTable GetAwards(string applicantKey)
        {
            DataTable dtResult = null;

            using (SqlConnection conn = new SqlConnection(Help.GetConnectionString("SRM")))
            {
                DataSet ds = new DataSet();
                SqlCommand cmd = conn.CreateCommand();
                SqlDataAdapter da = new SqlDataAdapter(cmd);

                cmd.CommandText = string.Format("SELECT * FROM SRM_ApplicantAwards_Tbl WHERE ApplicantKey = {0};", applicantKey);
                da.Fill(ds);

                dtResult = ds.Tables[0];
            }

            return dtResult;
        } // public static DataTable GetAwards(string applicantKey)


        [DataObjectMethodAttribute(DataObjectMethodType.Insert, true)]
        public static void InsertAwards(string applicantKey,
            string description, string awardingBody, string dateAwarded)
        {
            using (SqlConnection conn = new SqlConnection(Help.GetConnectionString("SRM")))
            {
                SqlCommand cmd = conn.CreateCommand();

                cmd.CommandText = "INSERT INTO SRM_ApplicantAwards_Tbl (ApplicantKey,Description,AwardingBody,DateAwarded) VALUES (@ApplicantKey,@Description,@AwardingBody,@DateAwarded);";
                cmd.Parameters.AddWithValue("@ApplicantKey", applicantKey);
                cmd.Parameters.AddWithValue("@Description", description);
                cmd.Parameters.AddWithValue("@AwardingBody", awardingBody);
                cmd.Parameters.AddWithValue("@DateAwarded", dateAwarded);

                conn.Open();
                cmd.ExecuteNonQuery();
            }
        } // public static void InsertLanguageProficiency(string applicantKey, string language, string ability, string proficiency)



        [DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
        public static void DeleteAwards(string awardsKey)
        {
            using (SqlConnection conn = new SqlConnection(Help.GetConnectionString("SRM")))
            {
                SqlCommand cmd = conn.CreateCommand();

                cmd.CommandText = "DELETE FROM SRM_ApplicantAwards_Tbl WHERE AwardsKey = @AwardsKey;";
                cmd.Parameters.AddWithValue("@AwardsKey", awardsKey);

                conn.Open();
                cmd.ExecuteNonQuery();
            }
        } // public static void InsertLanguageProficiency(string applicantKey, string language, string ability, string proficiency)


        //Description
        //AwardingBody
        //DateAwarded
        [DataObjectMethodAttribute(DataObjectMethodType.Update, true)]
        public static void UpdateAwards(string awardsKey,
            string description, string awardingBody, string dateAwarded)
        {
            using (SqlConnection conn = new SqlConnection(Help.GetConnectionString("SRM")))
            {
                SqlCommand cmd = conn.CreateCommand();

                cmd.CommandText = @"
UPDATE  SRM_ApplicantAwards_Tbl 
SET     Description = @Description, 
        AwardingBody = @AwardingBody, 
        DateAwarded = @DateAwarded 
WHERE   AwardsKey = @awardsKey;";

                cmd.Parameters.AddWithValue("@AwardsKey", awardsKey);
                cmd.Parameters.AddWithValue("@Description", description);
                cmd.Parameters.AddWithValue("@AwardingBody", awardingBody);
                cmd.Parameters.AddWithValue("@DateAwarded", dateAwarded);

                conn.Open();
                cmd.ExecuteNonQuery();
            }
        } // public static void UpdateAwards(string awardsKey,

    }
}